package com.sky.setmealdish.service.impl;

import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.setmealdish.mapper.SetMealDishMapper;
import com.sky.setmealdish.service.SetMealDishService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜品套餐关联 serviceImpl
 */
@Service
public class SetMealDishServiceImpl implements SetMealDishService {

    @Resource
    private SetMealDishMapper setMealDishMapper;



    /**
     * 套餐菜品关联
     *           根据菜品id集合 查询所关联的套餐集合
     * @param dishIds
     */
    @Override
    public List<Setmeal> selectSetMealListByDishIds(List<Long> dishIds) {
        return setMealDishMapper.selectSetMealListByDishIds(dishIds);
    }



    /**
     * 套餐菜品关联
     *           新增套餐菜品关联
     * @param setmealDish
     */
    @Override
    @Transactional(rollbackFor= Exception.class, propagation= Propagation.REQUIRED) //开启事务
    public Integer saveSetmealDish(SetmealDish setmealDish) {
        return setMealDishMapper.insertSetmealDish(setmealDish);
    }



    /**
     * 套餐菜品关联
     *           根据套餐ids 批量删除套餐菜品关联
     * @param setmealIds
     */
    @Override
    @Transactional(rollbackFor= Exception.class, propagation= Propagation.REQUIRED) //开启事务
    public Integer deleteBySetmealIds(List<Long> setmealIds) {
        return setMealDishMapper.deleteBySetmealIds(setmealIds);
    }



    /**
     * 套餐菜品关联
     *           根据套餐id 查询套餐菜品关联列表
     * @param setMealId
     */
    @Override
    public List<SetmealDish> selectBySetmealId(Long setMealId) {
        return setMealDishMapper.selectBySetmealId(setMealId);
    }


}
